<template>

  <div class="app-container">

    <div style="margin-top: 20px">

      检查项目
      <el-radio-group v-model="radio1">

        <el-radio-button label="乙肝五项"></el-radio-button>
        <el-radio-button label="血常规"></el-radio-button>
        <el-radio-button label="CT"></el-radio-button>
        <el-radio-button label="X光"></el-radio-button>
      </el-radio-group>
    </div>
    <el-form :model="queryParams" ref="queryForm" :inline="true" v-show="showSearch" label-width="68px">

      <el-form-item label="检查单号" prop="checkCode">
        <el-input
          v-model="queryParams.checkCode"
          placeholder="请输入检查单号"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>

      </el-form-item>
    </el-form>

    <el-table v-loading="loading" :data="postList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="检查单号" align="center" prop="checkCode" />
      <el-table-column label="项目名称" align="center" prop="examName" />
      <el-table-column label="患者姓名" align="center" prop="patiName" />
      <el-table-column label="检查状态" align="center" prop="checkStatus" />
      <el-table-column label="检查结果" align="center" prop="checkResult" />
      <el-table-column label="创建时间" align="center" prop="createTime" />
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">


          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleAdd(scope.row)"
            v-hasPermi="['check:result:index']"
          >录入结果</el-button>

        </template>
      </el-table-column>



    </el-table>

    <el-table>
      <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
    </el-table>


    <!--<pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />-->

    <!-- 录入结果对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="500px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="80px">
        <el-form-item label="检查结果">
          <el-input v-model="form.checkResult" type="textarea" placeholder="请输入检查内容"></el-input>
        </el-form-item>
      </el-form>

      <el-upload
        class="upload-demo"
        action="http://localhost:8080/hyysystem/patientinfo/upload"
        :on-success="handleSuccess"
        :on-error="handleError"
        :file-list="fileList"
        list-type="picture">
        <el-button size="small" type="primary">点击上传</el-button>
        <div slot="tip" class="el-upload__tip">只能上传jpg/png文件，且不超过500kb</div>
      </el-upload>


      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>

  </div>
</template>

<script>



import { listPost, getPost, delPost, addPost, updatePost, exportPost } from "@/api/check/result";
var id="";
var name="";

export default {
  name: "Post",
  data() {
    return {
        //图片地址

        fileList: [],


         //检查项目
        radio1: '乙肝五项',
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 岗位表格数据
      postList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 状态数据字典
      statusOptions: [],
      // 查询参数
      queryParams: {

          checkCode: undefined,

      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
          checkCode: [
          { required: true, message: "检查单号不能为空", trigger: "blur" }
        ]
      }
    };
  },
  created() {
    this.getList();
    this.getDicts("sys_normal_disable").then(response => {
      this.statusOptions = response.data;
    });
  },
  methods: {
      //图片地址

      handleError(file, fileList) {
          console.log(file, fileList);
      },
      handleSuccess(response,file,fileList) {

          name=file.name;
          console.log(file.name);
          console.log(fileList);
      },



      open2(){
          //获取选中的check_id的值
          var checkCode=document.getElementById("c1").value;
          startSuccess(checkCode).then(response=>{
              this.$message({
                  message:'开始成功',
                  type:'success'
              });
          })
      },

    /** 查询岗位列表 */
    getList() {
      this.loading = true;
      listPost(this.queryParams).then(response => {
        this.postList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },

    // 岗位状态字典翻译
    statusFormat(row, column) {
      return this.selectDictLabel(this.statusOptions, row.status);
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        postId: undefined,
        postCode: undefined,
          checkCode: undefined,
        postSort: 0,
        status: "0",
        remark: undefined
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.postId)
      this.single = selection.length!=1
      this.multiple = !selection.length
    },


    /** 录入图片确定按钮操作 */
    handleAdd(row) {
      //获取checkCode的值
      id=row.checkCode;

      this.reset();
      this.open = true;
      this.title = "录入检查结果";
    },



      /** 修改按钮操作 */
      // handleUpdate(row) {
      //     this.reset();
      //     const checkCode = row.checkCode || this.ids
      //     getPost(checkCode).then(response => {
      //         this.form = response.data;
      //         this.open = true;
      //         this.title = "录入图片";
      //     });
      // },



    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const postId = row.postId || this.ids
      getPost(postId).then(response => {
        this.form = response.data;
        this.open = true;
        this.title = "修改岗位";
      });
    },


    /** 提交按钮 */
    submitForm: function() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.postId != undefined) {
            updatePost(this.form).then(response => {
              this.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            console.log(this.form)
            addPost(this.form,id,name).then(response => {
              this.msgSuccess("录入成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const postIds = row.postId || this.ids;
      this.$confirm('是否确认删除岗位编号为"' + postIds + '"的数据项?', "警告", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning"
        }).then(function() {
          return delPost(postIds);
        }).then(() => {
          this.getList();
          this.msgSuccess("删除成功");
        })
    },
    /** 导出按钮操作 */
    handleExport() {
      const queryParams = this.queryParams;
      this.$confirm('是否确认导出所有岗位数据项?', "警告", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning"
        }).then(function() {
          return exportPost(queryParams);
        }).then(response => {
          this.download(response.msg);
        })
    }
  }
};
</script>
